package com.yao.mapper;

import com.yao.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Insert("insert into user values (#{id},#{username},#{password},#{birthday})")
    void save(User user);

    @Update("update user set username=#{username},password=#{password} where id=#{id}")
    void update(User user);

    @Delete("delete from user where id=#{id}")
    void delete(int id);

    @Select("select * from user where id=#{id}")
    User findById(int id);

    @Select("select * from user")
    List<User> findAll();

    @Select("select * from user")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "birthday",property = "birthday"),
            @Result(property = "orderList",javaType = List.class,column = "id",
            many = @Many(select = "com.yao.mapper.OrderMapper.findByUid"))
    })
    List<User> findAllUserAndOrder();

    @Select("select * from user")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "birthday",property = "birthday"),
           @Result(property = "roleList",column = "id",
           many = @Many(select = "com.yao.mapper.RoleMapper.findByUserId"))
    })
    List<User> findAllUserAndRole();
}
